Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add transaction filtering #272

Merged
merged 15 commits into from
Mar 22, 2024
Merged

feat: add transaction filtering #272

merged 15 commits into from
Mar 22, 2024

Conversation

dimazhornyk
Copy link
Contributor

What ❔

Introduces an opportunity to add an L1->L2 transaction filtering. The address of the filterer is being set through the Admin facet and then reused in Mailbox's _requestL2TransactionSender to ensure that the transaction can be sent.

Why ❔

Some partners want to run hyperchains with KYC/whitelisting of the addresses.

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.

@@ -226,6 +227,10 @@ contract MailboxFacet is ZkSyncStateTransitionBase, IMailbox {
function _requestL2TransactionSender(
BridgehubL2TransactionRequest memory _request
) internal nonReentrant returns (bytes32 canonicalTxHash) {
// Check that the transaction is allowed by the filterer (if the filterer is set).
if (s.transactionFilterer != address(0)) {
require(ITransactionFilterer(s.transactionFilterer).isTransactionAllowed(_request), "tf");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to submit the whole Transaction request for a check? This is gas-consuming, please only submit fields that makes sense to check (from?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial thought was to give as much flexibility as possible to the partners implementing the filters, but your point is valid so I reduced it to address sender, address contractL2, uint256 mintValue, uint256 l2Value

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the Stas comments, you may consider adding calldata selector this list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant selector (first 4 bytes of the calldata), not the whole calldata. This is to minimize the cost too

@StanislavBreadless wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is the selector going to be useful here? I thought that it would be more important to have the actual values of the calldata

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked with @vladbochok and it makes sense to pass the entire calldata

@@ -226,6 +227,15 @@ contract MailboxFacet is ZkSyncStateTransitionBase, IMailbox {
function _requestL2TransactionSender(
BridgehubL2TransactionRequest memory _request
) internal nonReentrant returns (bytes32 canonicalTxHash) {
// Check that the transaction is allowed by the filterer (if the filterer is set).
if (s.transactionFilterer != address(0)) {
require(ITransactionFilterer(s.transactionFilterer).isTransactionAllowed(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think it may make sense to require the entire BridgehubL2TransactionRequest? I am not sure about the impact on the cost of the transaction, but intuitively we might want to prevent users asking us for any additional parameters in the future for the tx validation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For instance, access to calldata may be the only option to prevent malicious contracts from bridging funds (as such txs would have L1SharedBridge as the sender)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a calldata to the list of params, but not the full request to save some gas

@StanislavBreadless StanislavBreadless merged commit cfc96e7 into dev Mar 22, 2024
19 checks passed
@StanislavBreadless StanislavBreadless deleted the feat-tx-filtering branch March 22, 2024 11:57
Copy link
Member

@thomas-nguy thomas-nguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Waiting for the hyperbridge design (ie L2<->L2 transactions) to see how hyperchains can behave pre-emptively to the transaction filtering.

Ideally there would be a way to tell the user that its transaction is going to fail before it actually reach the smart contracts on L1.

matzayonc pushed a commit to neotheprogramist/era-contracts that referenced this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants